
package com.example.a513;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.ArrayList;
import java.util.List;

import adpater.AnimationAdapter;
import entity.Animation;

public class ListViewActivity extends AppCompatActivity implements View.OnClickListener, AdapterView.OnItemClickListener, CompoundButton.OnCheckedChangeListener {
    private ListView listView;
    private List<Animation> list;
    private CheckBox ck_divider;
    private CheckBox ck_back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_list_view);
        listView = findViewById(R.id.list_view);
        ck_divider = findViewById(R.id.ck_divider);
        ck_back = findViewById(R.id.ck_back);
        list = Animation.getDefault();
        AnimationAdapter adapter = new AnimationAdapter(this, list);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(this);
        ck_back.setOnCheckedChangeListener(this);
        ck_divider.setOnCheckedChangeListener(this);


    }


    @Override
    public void onClick(View v) {

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Toast.makeText(this,list.get(position).getTitle(),Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (buttonView.getId() == R.id.ck_back){
            if (ck_back.isChecked()){
                listView.setSelector(R.drawable.list_selector);
            }else {
                Drawable drawable = getResources().getDrawable(R.color.white, getTheme());
                listView.setSelector(drawable);
            }
        }else if (buttonView.getId() == R.id.ck_divider){
             if (ck_divider.isChecked()){
                 Drawable drawable = getResources().getDrawable(R.color.black, getTheme());
                 listView.setDivider(drawable);
                 listView.setDividerHeight(1);
             }else {
                 listView.setDivider(null);
             }
        }
    }
}